﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SCRS.Bll;
using SCRS.Constants;

namespace SCRS.View
{
    public partial class LoginForm : Form
    {

        private readonly LoginBll loginBll = new LoginBll();

        public string UserName
        {
            get => input1.Text;
            set => input1.Text = value;
        }

        public string Password
        {
            get => input2.Text;
            set => input2.Text = value;
        }

        public LoginForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var dr = MessageBox.Show("是否确认退出程序?", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var account = loginBll.Login(UserName,Password);
            if (account == null)
            {
                MessageBox.Show("用户名或密码错误");
                return;
            }
            ScrsContext.SetProperty(LoginConstants.LOGIN_ACCOUNT,account);
            ScrsContext.SetProperty(LoginConstants.USER_NAME, UserName);
            this.Show(nameof(MainForm));
        }
    }
}
